package com.hison.controller;

import com.hison.domian.entity.User;
import com.hison.enums.AppHttpCodeEnum;
import com.hison.exception.SystemException;
import com.hison.service.BlogLoginService;
import com.hison.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: BlogLoginController
 * @Descripiton: TODO
 * @Author: 小郑
 * @Date： 2024/1/13 10:39
 * @Version：1.8
 **/
@RestController
public class BlogLoginController {
    /**
     * //BlogLoginService是我们在service目录写的接口
     */
    @Autowired
    private BlogLoginService blogLoginService;

    /**
     *  //ResponseResult是我们在huanf-framework工程里面写的实体类
     * @param user
     * @return {@link ResponseResult}
     */
    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user){
        if (!StringUtils.hasText(user.getUserName()) || !StringUtils.hasText(user.getPassword()) ){
            //提示必须传入用户名和密码才能登录
            throw  new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return blogLoginService.login(user);
    }

    @PostMapping("/logout")
    public ResponseResult logout(){
        return blogLoginService.logout();
    }
}